import java.util.Scanner;

public class Practice1 {
    //https://www.nowcoder.com/practice/3bcf72c738b6494bbe1ebe0ffde56152?tpId=230&tqId=40419&ru=/exam/oj
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int N = (int)1e4 + 1;
        //处理原数组转化成打家劫舍问题
        int[] hash = new int[N];
        for (int i = 0; i < n; i++) {
            int in = sc.nextInt();
            hash[in] += in;
        }
        int[] dp = new int[N];
        for(int i = 1;i < N;i++){
            if(i - 2 < 0){
                dp[i] = Math.max(hash[i],dp[i - 1]);
            }
            //当选到i时分为选和不选, 选 ==> 就要找dp[i- 2]的最大值
            //如果不选的话, 考虑dp[i- 1]的最大值
            //也可以分成g[i]和 f[i]来讨论两种不同的情况, 选与不选
            dp[i] = Math.max(dp[i - 2] + hash[i],dp[i - 1]);
        }
        System.out.println(dp[N]);
    }
}
